import 'package:flutter/material.dart';
import 'package:my_flutter_harmony/pages/home/home_page.dart';
import 'package:my_flutter_harmony/pages/user/user_page.dart';

import 'cart/cart_page.dart';
import 'cate/cate_page.dart';

class TabbarPage extends StatefulWidget {
  const TabbarPage({super.key});

  @override
  TabbarPageState createState() => TabbarPageState();
}

class TabbarPageState extends State<TabbarPage> {
  // 当前激活的索引
  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: const [
          HomePage(),
          CatePage(),
          CartPage(),
          UserPage(),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        backgroundColor: Colors.white,
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        unselectedFontSize: 12,
        unselectedItemColor: Colors.black,
        selectedFontSize: 12,
        selectedItemColor: Colors.red,
        onTap: (value) {
          setState(() {
            _currentIndex = value;
          });
        },
        items: [
          BottomNavigationBarItem(
            label: '首页',
            icon: Image.asset(
              'assets/tabbar/home.png',
              width: 24,
              height: 24,
            ),
            activeIcon: Image.asset(
              'assets/tabbar/home-active.png',
              width: 24,
              height: 24,
            ),
          ),
          BottomNavigationBarItem(
            label: '分类',
            icon: Image.asset(
              'assets/tabbar/cate.png',
              width: 24,
              height: 24,
            ),
            activeIcon: Image.asset(
              'assets/tabbar/cate-active.png',
              width: 24,
              height: 24,
            ),
          ),
          BottomNavigationBarItem(
            label: '购物车',
            icon: Image.asset(
              'assets/tabbar/cart.png',
              width: 24,
              height: 24,
            ),
            activeIcon: Image.asset(
              'assets/tabbar/cart-active.png',
              width: 24,
              height: 24,
            ),
          ),
          BottomNavigationBarItem(
            label: '我的',
            icon: Image.asset(
              'assets/tabbar/user.png',
              width: 24,
              height: 24,
            ),
            activeIcon: Image.asset(
              'assets/tabbar/user-active.png',
              width: 24,
              height: 24,
            ),
          ),
        ],
      ),
    );
  }
}
